#include "HttpProtocol.hpp"
#include "HttpSever.hpp"

void Login(HttpRequest &req, HttpResponse &resp)
{
   // 处理登录请求
   //login/username=admin&password=123456
    std::string args = req.Args();
   
    // 解析参数
    // 登陆成功返回
    std::string body = req.GetContent("wwwroot/success.html");
    resp.SetCode(200);
    resp.SetHeader("Content-Length", std::to_string(body.size()));
    resp.SetHeader("Content-Type", "text/html");
    resp.SetHeader("Set-Cookie", "usename=zhangsan&passwd=11111111");
    resp.SetBody(body);
}
int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        std::cout << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    auto httpserver = std::make_unique<HttpSever>(std::stoi(argv[1]));
    httpserver->Resgiter("/login", Login);
    httpserver->Start();
    

}